/*
 * This file is part of EasyCommander, http://www.easycommander.com
 * Copyright (C) 2007 Alex Petinov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.anotrend.easycommander.conf;

import java.io.File;
import java.util.WeakHashMap;

/**
 * @author Alexey Petinov
 * @version	$Revision: 8 $
 * 
 * $Id: ConfigurationManager.java 8 2007-07-21 09:12:37Z a.petinov $
 *
 */
public class ConfigurationManager {

	/** Path to the configuration file. */
    private static File configurationFile;

    /** Contains all registered configuration listeners, stored as weak references */
    private static WeakHashMap listeners = new WeakHashMap();

    /** Name of the configuration file */
    private static final String DEFAULT_CONFIGURATION_FILE_NAME = "preferences.xml";

    /**
     * Prevents the class from being instanciated.
     */
    private ConfigurationManager() {}


    /**
     * Adds the specified configuration listener to the list of registered listeners.
     *
     * <p>Listeners are stored as weak references so {@link #removeConfigurationListener(ConfigurationListener) removeConfigurationListener()}
     * doesn't need to be called for listeners to be garbage collected when they're not used anymore.</p>
     *
     * @param listener the listener to add to the list of registered listeners.
     */
    public static synchronized void addConfigurationListener(ConfigurationListener listener) {
        if(listener==null)
            return;
		
        listeners.put(listener, null);
    }

    /**
     * Removes the specified configuration listener from the list of registered listeners.
     *
     * @param listener the listener to remove from the list of registered listeners.
     */
    public static synchronized void removeConfigurationListener(ConfigurationListener listener) {
        listeners.remove(listener);
    }
}
